﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ymatou.CommonService;

namespace YmtAuth.Common.Extend
{
   public static class Action_Extend
    {
       public static T ActionWatch<T>(Func<T> func, string desc, int gteMilliseconds = 30)
       {
           var watch = Stopwatch.StartNew();
           var result = func();
           watch.Stop();

           if (watch.ElapsedMilliseconds >= gteMilliseconds)
               ApplicationLog.Debug(string.Format("{0}, run :{1:N0} ms.", desc, watch.ElapsedMilliseconds));

           return result;
       }

       public static void ActionWatch(Action action, string desc, int gteMilliseconds = 30)
       {
           var watch = Stopwatch.StartNew();
           action();
           watch.Stop();

           if (watch.ElapsedMilliseconds >= gteMilliseconds)
               ApplicationLog.Debug(string.Format("{0}, run :{1:N0}.", desc, watch.ElapsedMilliseconds));            
       }
    }
}
